Passed
Push — master ( 9a73f0...7331d4 )
by Huu-Phat
01:50 queued 11s
created

sagas.js ➔ postsSaga   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
1
import { call, put, takeLatest } from 'redux-saga/effects'
2
import { fetchPostSummary } from 'posts/api/fetch'
3
import { FETCH_POSTS } from 'core/state/actionType'
4
import { toSuccess, toError, toRequest } from 'core/state/utils'
5
6
function* fetchPosts() {
7
  try {
8
    const posts = yield call(fetchPostSummary)
9
    yield put({ type: toSuccess(FETCH_POSTS), payload: posts })
10
  } catch (e) {
11
    yield put({ type: toError(FETCH_POSTS), message: e.message })
12
  }
13
}
14
15
function* postsSaga() {
16
  yield takeLatest(toRequest(FETCH_POSTS), fetchPosts)
17
}
18
19
export default postsSaga
20